﻿using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Swiss;

namespace LsaTest
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class LsaTests
    {
        public LsaTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary> 
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        //static String CorpusDirectory = @"\Work\Lsi\01-Book\";
        //static String CorpusDirectory = @"\Work\Lsi\03-Handbook\";
        static String CorpusDirectory = @"\Work\Lsi\16-Aap\";

        //static String CorpusWildcard = "aap04pinche.txt"; //pinche-aap
        //static String CorpusWildcard = "Aap13Baardaap.txt"; //Zuid-India
        static String CorpusWildcard = "*.txt";

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestIndex()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.Index(Path.Combine(CorpusDirectory, CorpusWildcard));
            }
        }

        [TestMethod]
        public void TestZip()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.Zip(Path.Combine(CorpusDirectory, CorpusWildcard));
            }
        }

        [TestMethod]
        public void TestNonAlpha()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.Nonalpha(@".,!?':()[];=");
            }
        }

        [TestMethod]
        public void TestSpaces()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.Spaces();
            }
        }

        [TestMethod]
        public void TestHyphens()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.Hyphens();
            }
        }

        [TestMethod]
        public void TestWordLength()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.WordLength(3, 20);
            }
        }

        [TestMethod]
        public void TestStopList()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                //                String stoplist = Path.Combine(lsa.BaseDir, "stoplist.txt");

                //                File.WriteAllText(stoplist, @"Roll
                //Bread
                //Rock");
                String stoplist = Path.Combine(CorpusDirectory, "stopaap.stop");

                if (File.Exists(stoplist))
                {
                    lsa.StopList(stoplist);
                }
            }
        }

        [TestMethod]
        public void TestTerms()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.Terms();
            }
        }

        [TestMethod]
        public void TestOccurences()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                // lsa.Occurences(-1, -1, -1, -1);
                lsa.Occurences(2, -1, 2, -1);
            }
        }

        [TestMethod]
        public void TestTermMatrix()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.TermMatrix();
            }
        }

        [TestMethod]
        public void TestDecompose()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.Decompose();
            }
        }

        [TestMethod]
        public void TestEstimate()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.EstimateRank(-1, -1, 90);
            }
        }

        [TestMethod]
        public void TestReduce()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.Reduce(-1, 8);
            }
        }

        [TestMethod]
        public void TestReducedSpace()
        {
            using (Lsa.NET.Lsa lsa = new Lsa.NET.Lsa())
            {
                lsa.ReducedSpace();
            }
        }

        [TestMethod]
        public void TestDumpTiming1()
        {
            using (Profiling p = new Profiling())
            {
                for (Int32 i = 0; i < p.Count; i++)
                {
                    Console.WriteLine("{0} - {1}", i, p[i]);
                }
            }
        }

        //[TestMethod]
        //public void TestDumpTiming2()
        //{
        //    using (Profiling p = new Profiling())
        //    {
        //        foreach (String name in p)
        //        {
        //            Console.WriteLine(Profiling.ToString(name));
        //        }
        //    }
        //}

        //[TestMethod]
        //public void TestDumpTiming3()
        //{
        //using (Profiling p = new Profiling())
        //{
        //    foreach (String name in p)
        //    {
        //        Console.WriteLine(p[name]);
        //    }
        //}
        //}
    }
}
